<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../../css/api.css">
</head>

<body>
    <header class="aui-bar aui-bar-nav">
        <a class="aui-pull-left"><span class="aui-iconfont aui-icon-left" onclick="api.closeWin()"></span></a>
        <div class="aui-title">我的订单</div>
        <div id="calender"></div>
    </header>

    <div class="aui-tab" id="tab">
        <div class="aui-tab-item aui-active" onclick="order_all()">淘宝订单</div>
        <div class="aui-tab-item" onclick="order_booked()">商城订单</div>
        <div class="aui-tab-item" onclick="order_wait()">订单认领</div>
        <div class="aui-tab-item" onclick="order_failure()">订单号绑定</div>
    </div>

    <div class="aui-content aui-margin-t-10" id="order_list">
    </div>
    <div class="aui-content aui-margin-t-10" id="order_list_1" style="display:none;">
      
    </div>
    <div class="aui-content aui-margin-t-10" id="order_list_2" style="display:none;"></div>
    <div class="aui-content aui-margin-t-10" id="order_list_3" style="display:none;"></div>

</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript">
    var aFooterList = $api.domAll('#tab .aui-tab-item');
    var date=new Date;

    apiready = function() {
          if(!$api.getStorage('token')){
            location.href = './mine.html';
            return false;
          }
        var order_name = $api.byId('order_name');
        var order_number = $api.byId('order_number');
        var order_money = $api.byId('order_money');
        var order_rebate = $api.byId('order_rebate');
        var order_post = $api.byId('order_post');
        var order_list = $api.byId('order_list');
        
        var token = {
            token: $api.getStorage('token')
        }
        var changeIndexFrame = function(index) {
            for (var i = 0; i < 4; i++) {
                if (i == index) {
                    $api.addCls(aFooterList[index], 'aui-active');
                } else {
                    $api.removeCls(aFooterList[i], 'aui-active');
                }
            };
        };
        $api.byId('calender').innerHTML='<a href="" class="aui-pull-right">'+(date.getMonth()+1)+'月<span class="aui-iconfont aui-icon-calendar"></span></a>'

        window.order_all = function() {

            $api.byId('order_list').style = "display:block";
            $api.byId('order_list_1').style = "display:none";
            $api.byId('order_list_2').style = "display:none";
            $api.byId('order_list_3').style = "display:none";
            changeIndexFrame(0);
        }
        window.order_booked = function() {
            $api.byId('order_list').style = "display:none";
            $api.byId('order_list_1').style = "display:block";
            $api.byId('order_list_2').style = "display:none";
            $api.byId('order_list_3').style = "display:none";
            changeIndexFrame(1);
        }
        window.order_wait = function() {
            $api.byId('order_list').style = "display:none";
            $api.byId('order_list_1').style = "display:none";
            $api.byId('order_list_2').style = "display:block";
            $api.byId('order_list_3').style = "display:none";
            changeIndexFrame(2);
        }
        window.order_failure = function() {
            $api.byId('order_list').style = "display:none";
            $api.byId('order_list_1').style = "display:none";
            $api.byId('order_list_2').style = "display:none";
            $api.byId('order_list_3').style = "display:block";
            changeIndexFrame(3);
        }
        
        
        function setMyOrder() {
            api.ajax({
                url: 'http://www.mk517.com/webApi/myOrder.php',
                method: 'post',
                dataType: 'json',
                "headers": {
                    "Content-Type": "application/json;charset=utf-8"
                },
                data:{
                    body: token
                }
            }, function(ret, err) {
                
                if (ret) {
                  var status='';
                    for (var i = 0; i < ret.length; i++) {
                        order = ret[i];
                        if(order.order_post<=3){
                          status='待入账';
                        }
                        if(order.order_post==4){
                          status='已失效';
                        }
                        if(order.order_post==5){
                          status='已入账';
                        }
                        if (order.order_post) {
                           $api.byId('order_list').innerHTML += '<ul class="aui-list aui-media-list"><li class="aui-list-item aui-list-item-middle">' +
                               '<div class="aui-media-list-item-inner"><div class="aui-list-item-inner"><div class="aui-list-item-text">' +
                               '<div class="aui-list-item-title aui-font-size-18">' + order.order_name + '</div></div></div></li>' +
                               '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">订单号</div>' +
                               '<div class="aui-list-item-right aui-font-size-18">' + order.order_number + '</div></li>' +
                               '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">金额</div>' +
                               '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_money + '</div></li><li class="aui-list-item-text">' +
                               '<div class="aui-list-item-title aui-font-size-18">返利</div>' +
                               '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_rebate + '</div></li>' +
                               '<li class="aui-list-item-text">' +
                               '<div class="aui-list-item-title aui-font-size-18">状态</div>' +
                               '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">' + status + '</div></li></ul>'
                       }
                        if (order.order_post <= 3) {
                            $api.byId('order_list_1').innerHTML += '<ul class="aui-list aui-media-list"><li class="aui-list-item aui-list-item-middle">' +
                                '<div class="aui-media-list-item-inner"><div class="aui-list-item-inner"><div class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">' + order.order_name + '</div></div></div></li>' +
                                '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">订单号</div>' +
                                '<div class="aui-list-item-right aui-font-size-18">' + order.order_number + '</div></li>' +
                                '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">金额</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_money + '</div></li><li class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">返利</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_rebate + '</div></li>' +
                                '<li class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">状态</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">' + status + '</div></li></ul>'
                        }
                         if (order.order_post == 4) {
                            $api.byId('order_list_3').innerHTML += '<ul class="aui-list aui-media-list"><li class="aui-list-item aui-list-item-middle">' +
                                '<div class="aui-media-list-item-inner"><div class="aui-list-item-inner"><div class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">' + order.order_name + '</div></div></div></li>' +
                                '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">订单号</div>' +
                                '<div class="aui-list-item-right aui-font-size-18">' + order.order_number + '</div></li>' +
                                '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">金额</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_money + '</div></li><li class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">返利</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_rebate + '</div></li>' +
                                '<li class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">状态</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">' + status + '</div></li></ul>'
                        }
                        if (order.order_post == 5) {
                            $api.byId('order_list_2').innerHTML += '<ul class="aui-list aui-media-list"><li class="aui-list-item aui-list-item-middle">' +
                                '<div class="aui-media-list-item-inner"><div class="aui-list-item-inner"><div class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">' + order.order_name + '</div></div></div></li>' +
                                '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">订单号</div>' +
                                '<div class="aui-list-item-right aui-font-size-18">' + order.order_number + '</div></li>' +
                                '<li class="aui-list-item-text"><div class="aui-list-item-title aui-font-size-18">金额</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_money + '</div></li><li class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">返利</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">￥' + order.order_rebate + '</div></li>' +
                                '<li class="aui-list-item-text">' +
                                '<div class="aui-list-item-title aui-font-size-18">状态</div>' +
                                '<div class="aui-list-item-right aui-font-size-18 aui-text-danger">' + status + '</div></li></ul>'
                        }




                    }
                    //  if(order.)
                    changeIndexFrame(0);


                    // alert(JSON.stringify(ret));
                } else {
                    // alert(JSON.stringify(err));
                }
            });
        }
  
        setMyOrder();
    }
</script>

</html>
